\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{cstart}[2009/04/23 v1.0 CSTART Document]

% Passes and class options to the underlying article class
\def\@tocnewpage{}
\DeclareOption{tocnewpage}{\def\@tocnewpage{\vspace{-20mm}\clearpage}} 
\DeclareOption{guide}{\def\@guide{}} 
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{scrartcl}}
\ProcessOptions

\LoadClass[english,bibtotocnumbered,titlepage,10pt]{scrartcl}

%% Page layout
\RequirePackage[a4paper]{geometry}
\geometry{tmargin=2cm,bmargin=5cm,lmargin=2.4cm,rmargin=2.1cm}
\setlength{\headheight}{20mm}
\RequirePackage{multicol}
\tolerance=400
\RequirePackage{calc}

\RequirePackage[final]{graphicx}
\DeclareGraphicsRule{.pdftex}{pdf}{*}{}
\RequirePackage[usenames,dvipsnames]{color}

\RequirePackage[T1]{fontenc}
\RequirePackage[scaled]{helvet}
\renewcommand*\familydefault{\sfdefault} %% base font: sans serif
\DeclareFontFamily{T1}{lmss}{}

\usepackage{type1cm}
\usepackage{eso-pic}
\usepackage{ifdraft}

\ifdraft{
\AddToShipoutPicture{%
            \setlength{\@tempdimb}{.5\paperwidth}%
            \setlength{\@tempdimc}{.5\paperheight}%
            \setlength{\unitlength}{1pt}%
            \put(\strip@pt\@tempdimb,\strip@pt\@tempdimc){%
        \makebox(0,0){\rotatebox{45}{\textcolor[gray]{0.95}%
        {\includegraphics{layout/draft}
				}}}}%
}
}{}




%% Title page design

\def \@address{}
\def \@telephone{}
\def \@version{}
\def \@email{}
\def \@location{}
\def \@license{}

\def \@scndtitle{}
\def \@titleart{}

\newcommand \address[1]{\gdef\@address{#1}}
\newcommand \telephone[1]{\gdef \@telephone{#1}}
\newcommand \email[1]{\gdef \@email{#1}}
\newcommand \version[1]{\gdef \@version{#1}}
\newcommand \location[1]{\gdef \@location{#1}}
\newcommand \license[1]{\gdef \@license{#1}}
\newcommand \keywords[1]{\gdef \@keywords{#1}}%

\newcommand \scndtitle[1]{\gdef \@scndtitle{#1}}
\newcommand \titleart[1]{\gdef \@titleart{#1}}

\renewcommand{\abstract}[1]{\newsavebox{\@abstract}\sbox{\@abstract}{%
	\parbox{0.7\textwidth}{%
	\fontfamily{\familydefault}\selectfont%
	\large{\quad #1}%
}}}

\RequirePackage{textpos}

%%
% Title block
\ifdefined\@guide
	\renewcommand{\maketitle}{%
	\begin{titlepage}
		%%
		% Picture
		\begin{textblock*}{110mm}[0,0.3](-8mm,-\voffset-\topmargin-\headheight-\headsep-1in+.3\paperheight)
			\@titleart
		\end{textblock*}
		%%
		% Logo
		\begin{textblock*}{120mm}[1,0](\textwidth + 20mm,-25mm)
			\begin{minipage}[c]{75mm}
			\includegraphics[width=75mm]{layout/cstart-text}%
			\end{minipage}
			\hspace*{3mm}%
			\begin{minipage}[c]{30mm}
			\includegraphics[width=30mm]{layout/cstart-circle}%
			\end{minipage}
		\end{textblock*}
		%%
		% Title
		\begin{textblock*}{.60\textwidth}(.4\textwidth,.55\textheight)
			\linespread{1.25}%
			\raggedright%
			\fontfamily{lmssq}\selectfont%
			\begin{tabular}{@{}l@{\color{Gray}\vrule width 2.5mm\hskip 2mm}p{.9\textwidth}}%
				&\vspace{-2mm}
				\raggedright
				\LARGE\@title
			\end{tabular}
			\vskip 2em
			\begin{tabular}{@{\hskip 4.5mm}p{.9\textwidth}}%
				\LARGE%
				\raggedright
				\@scndtitle%
			\end{tabular}
			\vskip 2em%
			\begin{tabular}{@{\hskip 4.5mm}p{.9\textwidth}}%
				\Large%
				\@version\vskip -.2em%
				\@location\vskip -.2em%
			\end{tabular}
		\end{textblock*}
		%%
		% License
		\begin{textblock*}{.5\textwidth}(.4\textwidth,\textheight)\noindent\@license\end{textblock*}
	\end{titlepage}%
	\fontfamily{\familydefault}\selectfont
	\setcounter{footnote}{0}%
	}
\else
	\renewcommand{\maketitle}{%
	\begin{titlepage}
		%%
		% Title
		\begin{textblock*}{75mm}(5mm,-5mm)
			\linespread{1.25}%
			\raggedright
			\fontfamily{lmssq}\selectfont
			\parbox[t][30mm][t]{\textwidth}{\raggedright\LARGE\@title}
			\fontfamily{\familydefault}\selectfont
			\vskip 3em%
			{\large%
			\@author%
			\vskip 1em%
			\@email\vskip -.2em%
			\@date\vskip -.2em%
			\@version\vskip -.2em%
			\@location\vskip -.2em%
			}
		\end{textblock*}
		%%
		% Logo
		\begin{textblock*}{80mm}(90mm,-18mm)
			\centering
			\includegraphics[width=75mm]{layout/cstart-circle}%
			\vspace*{3mm}\newline%
			\includegraphics[width=75mm]{layout/cstart-text}%
		\end{textblock*}
		%%
		% License
		\begin{textblock*}{\textwidth}[.5,-.1](.5\textwidth,1.03\textheight)
			\centering\@license%
		\end{textblock*}
		%%
		% Abstract and rest
		\vspace{90mm}\vfil%
		\ifdefined\@abstract
		\hfill
			\begin{tabular}{l@{\hskip 2mm\color{Gray}\vrule width 2mm}l}%
				\usebox{\@abstract}&%
			\end{tabular}\par\vfil
		\fi
		\@tocnewpage
		\tableofcontents
	\end{titlepage}%
	\setcounter{footnote}{0}%
	}
\fi

%\ifdraft{%
%}{}


%% Section headers

\definecolor{titlecolor}{gray}{0.3}
\RequirePackage{titlesec}
\titleformat{\section}
	{\fontfamily{lmssq}\selectfont\large\bfseries\color{titlecolor}\raggedright}
	{\thesection}{0.9em}{}
\titleformat{\subsection}
	{\fontfamily{lmssq}\selectfont\bfseries\color{titlecolor}\raggedright}
	{\thesubsection}{0.4em}{}
\titleformat{\subsubsection}
	{\normalfont\bfseries\color{titlecolor}}
	{\thesubsection}{0.2em}{}

\ifdefined\@guide
	\let\chapter=\section
	\let\section=\subsection
	\let\subsection=\subsubsection
	\let\subsubsection=\paragraph
\fi

%% Header/Footer

\RequirePackage{fancyhdr}

\newcommand{\@logo}{\includegraphics[height=10mm]{layout/cstart-circle}\hspace{1mm}\includegraphics[height=9mm]{layout/cstart-text}}
\ifdraft{%
	\newcommand{\@headtext}{\it\@title\\\@author\quad\@date, \@version~--~draft}
}{
	\newcommand{\@headtext}{\it\@title\\\@author\quad\@date, \@version}
}
\newcommand{\@foottext}{\it\@location}

\pagestyle{fancy}
\fancyhf{} % remove all headers and footers
\fancyhead[LO,RE]{\@logo}
\fancyhead[C]{}
\fancyhead[RO,LE]{\@headtext}
\renewcommand{\headrulewidth}{0.4pt}
\fancyfoot[LO,RE]{\@foottext}
\fancyfoot[C]{}
\fancyfoot[RO,LE]{\thepage}
\renewcommand{\footrulewidth}{0.4pt}


%% Maths

\RequirePackage{amsmath}
\RequirePackage{amstext}
\RequirePackage{amssymb}

%%
% make 'l' be distinguishable from '1' in maths
\gdef\eLL{\ifnum\the\fam=-1
\ell\fi\ifnum\the\fam>-1
\mathcode`l="716C{}l\fi}
{\catcode`l=\active\gdefl{\eLL{}\hspace{0.2pt}}}
\mathcode`l="8000

%%
% Definitions

\newcommand{\e}{\mathrm{e}}
\newcommand{\SetN}{\mathbb{N}}
\newcommand{\SetZ}{\mathbb{Z}}
\newcommand{\SetC}{\mathbb{C}}
\newcommand{\SetR}{\mathbb{R}}
\newcommand{\diff}{\mathrm{d}}
\newcommand{\difffrac}[2]{\frac{\diff#1}{\diff#2}}
\newcommand{\E}[1]{\ensuremath{\cdot 10^{#1}}}


%% Code Blocks

\usepackage{listings}
\definecolor{babyblue}{rgb}{.96,0.98,0.99}
\lstset{tabsize=2,
flexiblecolumns=true,
breaklines=true,
breakatwhitespace=true,
numbers=left,
numberstyle=\tiny\sf,
basicstyle=,
xleftmargin=7.5mm,
%xrightmargin=15mm,
%frame=single,
%framerule=0.4pt,
%framexleftmargin=10mm,
%framexrightmargin=10mm,
framesep=1mm}



%% Other definitions

\RequirePackage[unicode=true, pdfusetitle, final,%
 bookmarks=true,bookmarksnumbered=false,bookmarksopen=false,%
 breaklinks=true,pdfborder={0 0 0},backref=false,colorlinks=false]{hyperref}

\def\labelitemi{\normalfont\bfseries{--}}


\endinput %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
